﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;

namespace DTO
{
    public class User
    {
        String id;
        String name;
        Boolean gender;
        DateTime birth;
        String avatarPath;
        String blogName;
        String blogDescription;
        String coverImagePath;
        String question1;
        String answer1;
        String question2;
        String answer2;
        String passWord;

     
        public User() { }

        /// <summary>
        /// Create DTO.User instance which specific ID.
        /// </summary>
        /// <param name="ID">User ID.</param>
        public User(String ID)
        {
            this.id = ID;
        }

        /// <summary>
        /// Create DTO.User instance using SqlDataReader object.
        /// </summary>
        /// <param name="reader">Object contains informations get from DB.</param>
        public User(SqlDataReader reader)
        {
            if (reader != null && !reader.IsClosed)
            {
                id = reader.GetString(0);

                if(!reader.IsDBNull(1))
                    name = reader.GetString(1);
                if (!reader.IsDBNull(2))
                    gender = reader.GetBoolean(2);
                if (!reader.IsDBNull(3))
                    birth = reader.GetDateTime(3);
                if (!reader.IsDBNull(4))
                    avatarPath = reader.GetString(4);
                if (!reader.IsDBNull(5))
                    blogName = reader.GetString(5);
                if (!reader.IsDBNull(6))
                    blogDescription = reader.GetString(6);
                if (!reader.IsDBNull(7))
                    coverImagePath = reader.GetString(7);
                if (!reader.IsDBNull(8))
                    question1 = reader.GetString(8);
                if (!reader.IsDBNull(9))
                    answer1 = reader.GetString(9);
                if (!reader.IsDBNull(10))
                    question2 = reader.GetString(10);
                if (!reader.IsDBNull(11))
                    answer2 = reader.GetString(11);
                passWord = reader.GetString(12);
                passWord = Convert.ToString(reader["Password"]);
            }
        }

        /// <summary>
        /// User ID.
        /// </summary>
        public String ID
        {
            set 
            {
                if (value == null || "".Equals(value))
                    throw new Exception("UserID is null.");
                else
                    this.id = value;
            }
            
            get { return this.id; }
        }

        /// <summary>
        /// Pass word
        /// </summary>
        public String PassWord
        {
            get { return passWord; }
            set { passWord = value; }
        }

        /// <summary>
        /// User name.
        /// </summary>
        public String Name
        {
            get 
            { return this.name; }
            set 
            {
                if (value == null || "".Equals(value))
                    throw new Exception("User name is null.");
                else
                    this.name = value;
            }
        }

        /// <summary>
        /// User's gender. This get True value if user is male.
        /// </summary>
        public Boolean Gender
        {
            get { return this.gender; }
            set { this.gender = value; }
        }

        /// <summary>
        /// User's birthday.
        /// </summary>
        public DateTime Birth
        {
            get { return this.birth; }
            set { this.birth = value; }
        }

        /// <summary>
        /// Path to user's avatar.
        /// </summary>
        public String AvatarPath
        {
            get { return this.avatarPath; }
            set { this.avatarPath = value; }
        }

        /// <summary>
        /// Blog name.
        /// </summary>
        public String BlogName
        {
            get { return this.blogName; }
            set { this.blogName = value; }
        }

        /// <summary>
        /// Blog description.
        /// </summary>
        public String BlogDescription
        {
            get { return this.blogDescription; }
            set { this.blogDescription = value; }
        }

        /// <summary>
        /// Path to cover image.
        /// </summary>
        public String CoverImagePath
        {
            get { return this.coverImagePath; }
            set { this.coverImagePath = value; }
        }

        /// <summary>
        /// First question for recovery password.
        /// </summary>
        public String Question1
        {
            get { return this.question1; }
            set
            {
                if (value == null || "".Equals(value))
                    throw new Exception("Input question is null.");
                else
                    this.question1 = value;
            }
        }

        /// <summary>
        /// Second question for recovery password.
        /// </summary>
        public String Question2
        {
            get { return this.question2; }
            set
            {
                if (value == null || "".Equals(value))
                    throw new Exception("Input question is null.");
                else
                    this.question2 = value;
            }
        }
        public String Answer1
        {
            get { return this.answer1; }
            set
            {
                if (value == null || "".Equals(value))
                    throw new Exception("Input answer is null.");
                else
                    this.answer1= value;
            }
        }

        /// <summary>
        /// Second answer for recovery password.
        /// </summary>
        public String Answer2
        {
            get { return this.answer2; }
            set
            {
                if (value == null || "".Equals(value))
                    throw new Exception("Input answer is null.");
                else
                    this.answer2 = value;
            }
        }
    }
}